#ifndef GNDEBUG_H
#define GNDEBUG_H
#include "GnSystemDefine.h"

typedef bool (*GnAssertFunc)(const char* pcExpression,
	const char* pcFile, const char* pcFunction, const int iLine);

class GNSYSTEM_ENTRY GnDebug
{
public:
	// This assertion is the generic platform-specific assert handler
	static bool DefaultAssertFail(
		const char* pcExpression,
		const char* pcFile,
		const char* pcFunction,
		const int iLine);

	// This assertion routine will simply write out a debug string. 
	// It will not trigger a breakpoint. This is useful for running 
	// automated tests.
	static bool SimpleAssertFail(
		const char* pcExpression,
		const char* pcFile,
		const char* pcFunction,
		const int iLine);

	static GnAssertFunc msGnAssertFunc;
};


#if defined(_PS3)
#if defined(__SPU__)
#define GnDebugBreakProcImpl() __asm__ volatile("stopd 0,1,1")
#else
#define GnDebugBreakProcImpl() __asm__ volatile("tw 31,1,1")
#endif
#elif defined(WIN32)
#define GnDebugBreakProcImpl() __debugbreak()
#elif defined(_XENON)
#define GnDebugBreakProcImpl() __debugbreak()
#else // #if defined(_PS3)
#error Platform undefined.
#endif // #if defined(_PS3)

inline bool GnDebugBreakProc() { GnDebugBreakProcImpl(); return false; }

#ifdef GNDEBUG
#define GnDebugBreak() GnDebugBreakProc()
#else // #ifdef GNDEBUG
#define GnDebugBreak() false
#endif // #ifdef GNDEBUG

#ifdef GNDEBUG
	#if defined(_PS3) && defined(__SPU__)
	#define GnAssertLine(assertValue) \
		((assertValue) ? true : GnDebugBreak())
	#else
	#define GnAssertLine(assertValue) assert(assertValue)/* \
		((boolean_expresion) ? true : \
		GnAssertFail::ms_pfnGnAssertFailProc( \
	#boolean_expresion, __FILE__, __FUNCTION__, __LINE__))*/
	#endif
#else // #ifdef GNDEBUG
#define GnAssertLine(value) false
#endif // #ifdef GNDEBUG


#ifdef GNDEBUG
#define GnVerify(condition) GnAssertLine(condition)
#define GnAssert(boolean_expresion) ((void)GnAssertLine(boolean_expresion))
#else // #ifdef GNDEBUG
#define GnVerify(condition) (condition)
#define GnAssert(boolean_expresion) GNNOOP
#endif // #ifdef GNDEBUG

#endif // GNDEBUG_H
